local GameResultView = class("GameResultView",function()
	return display.newNode()
end)

local boxSize = cc.size(90,90)

function GameResultView:ctor(args)
    local text = ""
    if args.ok == 1 then
        text = args.userid.."胡了！"
    elseif args.ok ==2 then
        text = args.userid.."逃跑了！"
    end
    local width =display.width
    local height= display.height
    local listWidth = width-100*2
 

	args.user={{name="test1"},{name="test2"},{name="test3"}}
	self:setTouchEnabled(true)

	display.newColorLayer(cc.c4b(100,100,100,100)):addTo(self)

    cc.LayerColor:create(cc.c4b(200, 200, 200, 120),listWidth,display.height-100)
    :align(display.CENTER, 100, 50)
    :addTo(self)
 
    cc.ui.UILabel.new({
           UILabelType = 2, text = text, font="fonts/fzcyt.ttf",size = 64})
       :align(display.CENTER, display.cx, display.height-100)
        :setColor(cc.c3b(247, 14, 107))
       :addTo(self)

    cc.LayerColor:create(cc.c4b(100, 200, 100, 120),listWidth,100)
    :align(display.CENTER, 100, display.height-250)
    :addTo(self)

	 self.lv = cc.ui.UIListView.new {
    -- bg = "login_bg.png",
    viewRect = cc.rect(100, display.height-450, listWidth, 200),
    direction = cc.ui.UIScrollView.DIRECTION_VERTICAL}
    -- :onTouch(handler(self, self.touchListener))
    :addTo(self)

    --玩家，糊数，得分，牌形
    local titles = {"玩家","糊数","得分","牌形"}
    local itemWidth = listWidth/4
    for i=1,#args.user+1 do
    	local item = self.lv:newItem()
    	local content = display.newNode()
    	content:setContentSize(listWidth, 40)

    	if i==1 then
    		 cc.LayerColor:create(cc.c4b(240,240,240,255),listWidth,40):addTo(content)
    		 local labelColor = cc.c4b(237, 137, 7, 255)
    		for j=1,4 do
				cc.ui.UILabel.new(
                    {text = titles[j],
                    size = 20,
                    color = labelColor}):align(display.CENTER, itemWidth*j-itemWidth/2, 20):addTo(content)
    		end
    	else
    		cc.LayerColor:create(cc.c4b(185,217,253,255),listWidth,40):addTo(content)
    		local labelColor = cc.c4b(0,0,0, 255)
    		local user = args.user[i-1]
    		local items = {user.name,"12","1000","清湖"}
    		for k=1,4 do
				cc.ui.UILabel.new(
                    {text = items[k],
                    size = 20,
                    color = labelColor}):align(display.CENTER, itemWidth*k-itemWidth/2, 20):addTo(content)
    		end
    	end
	 	item:addContent(content)
	    item:setItemSize(listWidth, 40)
	    self.lv:addItem(item)
    end
    self.lv:reload()

    cc.ui.UIPushButton.new("Button01.png", {scale9 = true})
        :setButtonSize(100, 40)
        :setButtonLabel(cc.ui.UILabel.new({text = "退出"}))
        :onButtonPressed(function(event)
            event.target:setScale(1.1)
        end)
        :onButtonRelease(function(event)
            event.target:setScale(1.0)
        end)
        :onButtonClicked(function()
            self:removeSelf()
            args.close()
        end)
        :pos(display.width-150, display.height-100/2-20)
        :addTo(self)

end

return GameResultView